//
//  CommentHeaderSectionView.m
//  danpin
//
//  Created by chuangjia on 20/6/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "CommentHeaderSectionView.h"
#import "viewconfig.h"
@interface CommentHeaderSectionView()

@property (nonatomic, strong) UIButton *btnGood;
@property (nonatomic, strong) UIImageView *imgBorderView1;
@property (nonatomic, strong) UIImageView *imgBorderView2;
@property (nonatomic, strong) UIImageView *imgBorderView3;
@property (nonatomic, strong) UIImageView *imgBorderView4;
@end

@implementation CommentHeaderSectionView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor=[UIColor whiteColor];
        //
        _btnGood = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnGood setTitle:@"名称" forState:UIControlStateNormal];
        _btnGood.backgroundColor =[UIColor colorWithRed:0.176 green:0.463 blue:0.627 alpha:1];
        [_btnGood setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btnGood.titleLabel.font = FONT(14);
        
        [_btnGood addTarget:self action:@selector(goodAction:) forControlEvents:UIControlEventTouchUpInside];
        UIEdgeInsets edge = _btnGood.contentEdgeInsets;
        edge.left += PHOTO_FRAME_WIDTH;
        edge.right+= PHOTO_FRAME_WIDTH;
        _btnGood.contentEdgeInsets = edge;
        _btnGood.layer.cornerRadius = 3;//(值越大，角就越圆)
        _btnGood.layer.masksToBounds = NO;
        _btnGood.layer.rasterizationScale = [UIScreen mainScreen].scale;
        _btnGood.layer.shouldRasterize = YES;
        _btnGood.layer.shadowColor = [UIColor blackColor].CGColor;
        _btnGood.layer.shadowOffset = SHADOW_OFFSET_OF_PAILIDE;
        _btnGood.layer.shadowOpacity = 0.6;// 0.6;
        _btnGood.layer.shadowRadius = 0.3;//阴影半径，默认3

        //
        _imgBorderView3 =[[UIImageView alloc] initWithFrame:CGRectZero];
        _imgBorderView3.image =[UIImage imageNamed:@"border_03.png"];
        [self addSubview:_imgBorderView3];
        [self addSubview:_btnGood];
        _imgBorderView2 =[[UIImageView alloc] initWithFrame:CGRectZero];
        _imgBorderView2.image =[UIImage imageNamed:@"border_02.png"];
        [self addSubview:_imgBorderView2];
     
        _imgBorderView1 =[[UIImageView alloc] initWithFrame:CGRectZero];
        _imgBorderView1.image =[UIImage imageNamed:@"border_01.png"];
        [self addSubview:_imgBorderView1];

    }
    return self;
}
-(void)dealloc
{
    DLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    float fTop = 0;
    fTop += PHOTO_FRAME_WIDTH ;
    fTop += PHOTO_TIME_PADDING ;
    
    NSString* strGood =@"发表点评";
    if(strGood && [strGood isKindOfClass:[NSString class]] && [strGood length] > 0)
    {
        
        _btnGood.hidden = NO;
        [_btnGood setTitle:strGood forState:UIControlStateNormal];
        CGSize size=[strGood sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]}];
        
        
        float fGoodWidth = ceil(size.width )+ PHOTO_FRAME_WIDTH*2 + 1;
        _btnGood.frame =  CGRectMake(DEVICE_WIDTH-fGoodWidth-PHOTO_FRAME_WIDTH, 0, fGoodWidth, CAT_BUTTON_HEIGHT);
        
        if( CGAffineTransformIsIdentity(_btnGood.transform))
        {
            
            float fRotation = ((float)(arc4random()%50)) /10000;
            if(((int)(fRotation * 10000)) % 2)
            {
                fRotation = -fRotation;
            }
            
            if( fRotation > 0)
            {
                CGRect rc = _btnGood.frame;
                rc.origin.y += (int)fRotation%(int)PHOTO_TIME_PADDING;
                _btnGood.frame = rc;
            }
            _btnGood.transform = CGAffineTransformMakeRotation(M_PI * fRotation);
        }
    }
    else
    {
        _btnGood.hidden = YES;
    }
    
    fTop += TIME_HEIGHT;
    float fBackViewTop = 0;
  
    fBackViewTop = fTop + PHOTO_TIME_PADDING*2;
    _imgBorderView3.frame = CGRectMake(0, fBackViewTop - BOOK_FRAME, DEVICE_WIDTH, BOOK_FRAME);
    _imgBorderView2.frame = CGRectMake(0, fBackViewTop - BOOK_FRAME, DEVICE_WIDTH, BOOK_FRAME);
    _imgBorderView1.frame = CGRectMake(0, fBackViewTop - BOOK_FRAME, DEVICE_WIDTH, BOOK_FRAME);

    
}
-(void)goodAction:(id)sender
{
    
}
@end
